package com.test.hibernate;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class SessionFactoryManager {
	private static Configuration configuration =null;
	private static SessionFactory sessionFactory=null;
	private static String hibernateConfigFile=null;
	
	public static SessionFactory openSessionFactory(){
		configuration =new Configuration().configure(hibernateConfigFile);
		System.out.println("-----in SessionFactor hibernateConfigFile="+hibernateConfigFile);
		sessionFactory = configuration.buildSessionFactory();
		return sessionFactory;
	}
	
	public static void closeSessionFactory(){
		if(sessionFactory!=null && sessionFactory.isClosed()==false){
			sessionFactory.close();
		}
	}
	
	public static void setHibernateConfigFile(String hibernateConfigFile) {
		SessionFactoryManager.hibernateConfigFile = hibernateConfigFile;
	}
}
